package com.software.graduationproject.modules.marketers.web;

import com.baomidou.mybatisplus.core.metadata.Page;

import com.software.graduationproject.commons.select.Select;
import com.software.graduationproject.commons.util.Result;
import com.software.graduationproject.commons.util.Results;
import com.software.graduationproject.modules.marketers.object.MarketersCommentVo;
import com.software.graduationproject.modules.marketers.object.MarketersVo;
import com.software.graduationproject.modules.marketers.service.MarketersService;
import com.software.graduationproject.modules.marketers.object.MarketersCreateQo;

import com.v2coding.validate.CreateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * MarketersController : 商家表
 * ---------------------------------------------------------------------------------------------------------------------
 */
@Validated
@RestController
@RequestMapping("/Marketers/Marketers")
@Api(value = "API - 商家表", tags = {"商家表接口"})
public class MarketersController {

    @Autowired
    private MarketersService marketersService;

    @PostMapping("/create")
    @ApiOperation("新增商家")
    public Result createQo(@RequestBody @Validated(CreateGroup.class) MarketersCreateQo marketersCreateQo) {
        marketersService.createQo(marketersCreateQo);
        return Results.success();
    }

    @GetMapping("/select")
    @ApiOperation("查询商家详情")
    public Result<MarketersVo> selectVo(Long id) {
        MarketersVo marketersVo = marketersService.selectVo(id);
        return Results.success(marketersVo);
    }

    @GetMapping("/selectList")
    @ApiOperation("查询商家表列表")
    public Result<List<MarketersVo>> selectListVo(@ApiIgnore Select select) {
        List<MarketersVo> marketersVoList = marketersService.selectListVo(select);
        return Results.success(marketersVoList);
    }

    @GetMapping("/selectPage")
    @ApiOperation("查询商家表分页")
    public Result<Page<MarketersVo>> selectPageVo(@ApiIgnore Select select) {
        Page<MarketersVo> marketersVoPage = marketersService.selectPageVo(select);
        return Results.success(marketersVoPage);
    }

    @GetMapping("/searchList")
    @ApiOperation("搜索框查询商家列表")
    public Result<List<MarketersVo>> searchAllBySelect(@ApiIgnore Select select) {
        List<MarketersVo> marketersVoList = marketersService.searchAllBySelect(select);
        return Results.success(marketersVoList);
    }

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public Result upload(@RequestPart("file") MultipartFile file) {
        String upload = marketersService.upload(file);
        return Results.success(upload);
    }

    @GetMapping("/selectMarketersComment")
    @ApiOperation("查询商家评价")
    public Result<MarketersCommentVo> selectMarketersComment(Long id) {
        MarketersCommentVo marketersCommentVo = marketersService.selectMarketersComment(id);
        return Results.success(marketersCommentVo);
    }
}
